import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo5 {
    public static void main(String[] args) throws SQLException {

        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("cjc123456");

        Connection connection = dataSource.getConnection();

        // 1. 新增貂蝉同学的借阅记录：诗经，从2019年9月25日17:50到2019年10月25日17:50
        String sql1 = "insert into borrow_info values(null, 10, 3, '2019-9-25 17:50:00', '2019-10-25 17:50:00')";
        // 2. 查询计算机分类下的图书借阅信息
        String sql2 = "select borrow_info.id, student.name, borrow_info.book_id, book.name, borrow_info.start_time, borrow_info.end_time  from borrow_info, book, category, student where borrow_info.book_id = book.id and book.category_id = category.id and student.id = borrow_info.student_id  and category.id = 3";
        // 3. 修改图书《深入理解Java虚拟机》的价格为61.20
        String sql3 = "update book set price = 61.20 where name = '深入理解Java虚拟机'";
        // 4. 删除id最大的一条借阅记录
        String sql4 = "delete from borrow_info where id = max(id)";
    }
}
